using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Dimok.Data.Database;
using Dimok.Exceptions;
using Dimok.User;

namespace Dimok.GLRules{
	public class ShowCondition : System.Web.UI.Page{
		protected Literal ltrField;
		protected Literal ltrSrc;
		protected Literal ltrUnitEnums;
		protected HtmlSelect selCondValue;
		protected HtmlSelect selCond;
		protected UserObject uox = new UserObject();
		protected int ruleID = 0;
		private void Page_Load(object sender, System.EventArgs e){
			try{
				this.Context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
				ruleID = UserObject.GetQueryParam("RuleID") != "" ? int.Parse(Request["RuleID"]): 0;
				int mode = int.Parse(Request["mode"]);
				int programID = int.Parse(Request["ProgramID"]);
				if( mode == 3 ){
					ltrSrc.Text = SQLHelperEx.XmlInnerText(SQLHelperEx.ExecuteDataset(uox.db_GL,CommandType.Text,@"
DECLARE @PID int SELECT @PID = ProgramID FROM t_GLRules WHERE ID=@RuleID
SELECT ColumnID,Condition, Value, Value1, ISNULL(Label,'') Label,IsEmpty FROM GL_Rules(@PID) WHERE ID=@RuleID",new SqlParameter("@RuleID",ruleID)));
					SQLHelperEx.SELECT(selCondValue,GL.UnitEnums(ruleID),"Name","ID");
				}
				else
					ltrSrc.Text = SQLHelperEx.XmlInnerText(uox.db,"SELECT '' ColumnID,'' Condition, '' Value, '' Value1, '' Label, 0 IsEmpty");

				ltrField.Text = (new WS()).FieldsList(programID,false);
				ltrUnitEnums.Text = SQLHelperEx.XmlInnerText(GL.UnitEnums());
				SQLHelperEx.SELECT(selCond,uox.db_GL,"SELECT * FROM t_Condition","Unicode","ID");
			}catch(Exception exc){ throw new ClientException(exc); }
		}
		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
	}
}
